package 双指针;

import java.util.Scanner;

public class test3 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        System.out.println(isHappy(n));
    }
    public static boolean isHappy(int n){
        //使用快慢双指针,因为循环且1的平方也是1,所以两个指针总会有数值相等的时候
        int slow = n,fast = getResult(n);
        while (slow!=fast){
            // slow永远走一步,fast永远走两步
            slow = getResult(slow);
            fast = getResult(getResult(fast));
        }
        return slow==1; //进行最后的判断
    }
    public static int getResult(int n){
        int sum = 0;
        while (n!=0){
            int flag = n%10;
            sum+=(flag*flag);
            n/=10;
        }
        return sum;
    }
}
